import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		token: '',
		serviceSearchBarText:'',
		addressData:{}
	},
	mutations: {
		login(state, provider) {

			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
			console.log(state.userInfo);
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			state.token = '';
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		token(state,token){
			state.token=token
		},
		changeIcon(state,ownerIcon){
			state.userInfo.ownerIcon=ownerIcon
		},
		changeServiceSearchBarText(state,text){
			state.serviceSearchBarText=text
		},
		addressChoose(state,address){
			state.addressData=address
		},
		//清空所有的数据除了登录的数据
		clearAll(state){
			state.token=''
			state.serviceSearchBarText=''
			state.addressData={}
		}
	},
	actions: {

	}
})

export default store
